export default function nestTokens(tokens) {
    let nestedTokens = []
    // 收集器
    let collector = nestedTokens
    // 保存child, 进栈、出栈操作
    let sections = []

    for(let idx = 0; idx < tokens.length; idx++) {
        let token = tokens[idx]
        let key = token[0]

        switch(key) {
            case '#':
                collector.push(token)
                sections.push(token)
                collector = token[2] = []
                break;
            case '/':
                // 移动到上一个child
                sections.pop();
                collector = sections.length > 0 ? sections[sections.length - 1][2] : nestedTokens;
                break;
            default:
                collector.push(token)
                break;
        }
    }

    return nestedTokens
}